package com.hspedu.innerclass;

public class AnonymousInnerClassDetail {
    public static void main(String[] args) {
        Outer05 outer05 = new Outer05();
        outer05.f1();
    }
}


class Outer05 {
    private int n1 = 99;

    public void f1() {
        //创建一个基于类的匿名内部类
        Person person = new Person() {
            @Override
            public void hi() {
                System.out.println("匿名内部类重写了 hi()");
                System.out.println("n1=" + n1);
            }
        };
        person.hi();//动态绑定 Outer05$1

        //也可以直接调用
        new Person() {
            @Override
            public void hi() {
                System.out.println("hi() ...");
            }

            @Override
            public void hello(String str) {
                super.hello(str);
            }
        }.hello("jack");
    }
}

class Person {
    public void hi() {
        System.out.println("Person hi()");
    }

    public void hello(String str) {
        System.out.println("Person hello() " + str);
    }
}